package bag;
//自定义异常
class NameException extends RuntimeException{
    public NameException(String s){//写构造方法
        super(s);
    }
}
class PasswordException extends RuntimeException{
    public PasswordException(String s){
        super(s);
    }
}

public class Demo {
    public static final String name = "bit";
    public static final String password = "123";

    public static void login(String name,String password)throws NameException,PasswordException {
        if(!Demo.name.equals(name)){//需要在上面声明一下
            throw new NameException("用户名错误");
        }
        if(!Demo.password.equals(password)){//不同的时候
            throw new PasswordException("密码错误");
        }
    }


    public static void main(String[] args)throws NameException,PasswordException {
        try{
            login("bit","123");
            System.out.println("登陆成功");
        }catch (NameException e){
            e.printStackTrace();
            System.out.println("用户名错误");
        }catch (PasswordException e){
            e.printStackTrace();
            System.out.println("密码错误");
        }finally {
            System.out.println("finally执行了");
        }

    }
}
